﻿using System;
using System.Windows.Data;

namespace ImageLib.Shell.ValueConverter
{
    class MatchToBoolConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (parameter == null) { return null; }

            if (value == null) { return false; }

            return object.Equals(value, parameter);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (parameter == null) { return null; }

            bool boolValue = false;

            if (bool.TryParse(value.ToString(), out boolValue))
            {
                return boolValue ? parameter : null;
            }

            return null;
        }

        #endregion
    }
}